package com.lemon.smartsafety.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.utils.StringUtil;
import com.lemon.smartsafety.view.dialog.adapt.SingleTextAdapt;
import com.lemon.smartsafety.view.list.MyListView;

import java.util.ArrayList;
import java.util.List;



/**
 * 项目名称：up_exec_law
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/6/18 10:36
 * 修改人：Fargo
 * 修改时间：2016/6/18 10:36
 * 修改备注：
 */
public class DialogSingleChose {

    public interface ContentBack {
        public void callBackFunction(int item,String strContent);

    }

    private TextView txt_complete;
    private MyListView listView;


    private LinearLayout lineTitle;
    private Dialog upVSDialog;
    private ContentBack mContentBack = null;
    private SingleTextAdapt singleTextAdapt;

    private List<String> mList;

    private Context context;


    public DialogSingleChose(Context context) {
        this.context = context;
    }

    /**
     *** 初始化
     */
    public void init(List<String> strList ) {

        mList=new ArrayList<>();
        mList=strList;

        upVSDialog = new Dialog(context, R.style.dialog_style);
        upVSDialog.setContentView(R.layout.dialog_single_chose);
        Window win = upVSDialog.getWindow();
        win.setGravity(Gravity.CENTER);
        win.setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        upVSDialog.setCanceledOnTouchOutside(true);

        listView = (MyListView) upVSDialog.findViewById(R.id.listView);
        txt_complete = (TextView) upVSDialog.findViewById(R.id.txt_complete);


        singleTextAdapt=new SingleTextAdapt(context, StringUtil.transList(mList));
        listView.setAdapter(singleTextAdapt);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (mContentBack != null) {
                    mContentBack.callBackFunction(position,mList.get(position));
                }
                upVSDialog.dismiss();
            }
        });



    }


    public void show(final ContentBack contentBack) {

        mContentBack = contentBack;
        try {
            if (upVSDialog == null || upVSDialog.isShowing()) {
                return;
            }
            upVSDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
